package com.handpay.zztong.hp.notification.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.handpay.framework.utils.CommonUtils;
import com.handpay.zztong.hp.R;
import com.handpay.zztong.hp.base.activity.ZZTongActivity;
import com.handpay.zztong.hp.bean.ActionBar;
import com.handpay.zztong.hp.db.ormlite.DataBaseModel;
import com.handpay.zztong.hp.notification.model.NoticeBody;
import com.handpay.zztong.hp.notification.widget.XRTextView;

import static com.handpay.framework.utils.CommonUtils.StringFilter;

public class NoticeDetailActivity extends ZZTongActivity {
    private LinearLayout ndText;
    private TextView ndTitle, ndTime;
    //    private NoticeDataHelper noticeDB;
    private DataBaseModel dataBaseModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_notice_detail);
        super.onCreate(savedInstanceState);
        dataBaseModel =DataBaseModel.getInstance(this);
        initView();
    }

    private void initView() {
        ndTitle = (TextView) findViewById(R.id.notice_detail_title);
        ndTime = (TextView) findViewById(R.id.notice_detail_time);
        ndText = (LinearLayout) findViewById(R.id.notice_detail_text);
        NoticeBody notice = getIntent().getParcelableExtra("noticInfo");
        if (notice != null) {
            ndTitle.setText(getString(R.string.new_notice_detail_title_text) + notice.getTitle());
            ndTime.setText(CommonUtils.formatTime(notice.getTime()));
            XRTextView textview = new XRTextView(this, getResources().getDimension(R.dimen.normal_text_size), Color.rgb(71, 71, 71), CommonUtils.dp2px(20), CommonUtils.dp2px(20), 0, 0);
            String text = notice.getContent();
            textview.setText(StringFilter(TextUtils.isEmpty(text) ? "" : text));
            ndText.addView(textview, new LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            if (!notice.isRead()) {
                notice.setRead(true);
                dataBaseModel.updateNotice(notice);
            }
        }
    }

    @Override
    public ActionBar getActivityActionBar() {
        return new ActionBar(getString(R.string.new_notice_detail_title), true);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        noticeDB.close();
    }
}
